# Maintainer: Philipp Smirnov https://github.com/sad-poet

_realname=gnatdoc
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=25.0.0
pkgrel=3
pkgdesc="GNAT documentation generation tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/AdaCore/gnatdoc"
msys2_references=(
  'aur: gnatdoc'
  'gentoo: dev-ada/gnatdoc'
)
license=('spdx:GPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (Apache-2.0 WITH LLVM-exception)')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-ada"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-core"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-gmp"
         "${MINGW_PACKAGE_PREFIX}-gnatcoll-iconv"
         "${MINGW_PACKAGE_PREFIX}-langkit_support"
         "${MINGW_PACKAGE_PREFIX}-libadalang"
         "${MINGW_PACKAGE_PREFIX}-libgpr"
         "${MINGW_PACKAGE_PREFIX}-libvss"
         "${MINGW_PACKAGE_PREFIX}-markdown"
         "${MINGW_PACKAGE_PREFIX}-xmlada")
makedepends=("${MINGW_PACKAGE_PREFIX}-gprbuild")
source=("https://github.com/AdaCore/gnatdoc/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('970b29549f8b762d5cb35534352d7eb6747af6e7c22c847b79d84e3ee4739e91')

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}"/build-${MSYSTEM}
  cd "${srcdir}"/build-${MSYSTEM}

  gprbuild -p -P gnat/libgnatdoc.gpr \
    -j"$(nproc)" \
    -XBUILD_MODE=prod \
    -XLIBRARY_TYPE=relocatable

  gprbuild -p -P gnat/gnatdoc.gpr \
    -j"$(nproc)" \
    -XBUILD_MODE=prod \
    -XLIBRARY_TYPE=relocatable
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  gprinstall -f -p -P gnat/libgnatdoc.gpr \
    --prefix="${pkgdir}${MINGW_PREFIX}" \
    -XBUILD_MODE=prod \
    -XLIBRARY_TYPE=relocatable \
    --build-var=LIBRARY_TYPE \
    --build-name=relocatable

  gprinstall -f -p -P gnat/gnatdoc.gpr \
    --prefix="${pkgdir}${MINGW_PREFIX}" \
    -XBUILD_MODE=prod \
    -XLIBRARY_TYPE=relocatable \
    --build-var=LIBRARY_TYPE \
    --build-name=relocatable

  install -Dm644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" \
    "${srcdir}/${_realname}-${pkgver}"/LICENSE*
}
